y<template>
	<view style="padding: 30rpx;"> 
		<view class="Box" >
			<image 	class="headImage"
					:src="userprof.avatar"
					mode="widthFix"
					style="max-width: 60px; max-height: 60px; background-color: aqua;">
			</image>
			
			<view class="userDetail">
				<text>
					昵称：{{userprof.name}}
				</text>
				
				<text style="margin-top: 6%;">
					简介：<text style="color: gray; word-break: break-all;">{{userprof.information}}</text>
				</text>
			</view>
		</view>
		
		<view class="Box1">
			<text>
				他的笔记：
			</text>
			
			
			<view class="note" v-for="(item, index) in notes" :key="index" 
				@click="goNoteView(item.note_id, item.file)">
				<view class="title">{{ item.title }}</view>
				<view class="summary">{{ item.summary }}</view>
			</view>
			
			<view style="margin-top: 5%;display: flex">
				<button style="background-color: white" @click="addFriend">
					添加好友
				</button>
				<button style="background-color: white" @click="sendMessage">
					发消息
				</button>
			</view>
			
		</view>
	</view>
</template>

<script>
	import config from '@/config.js';
	export default {
		data() {
			return {
				userprof:{
					avatar: null, 
					name: '朋友1', username: '1', introduction: '介绍绍绍绍绍绍绍绍绍绍绍绍绍绍绍绍绍绍绍绍绍绍绍绍'
				},
				notes: [
					{title: '整挺好吧', summary: '摘要要要要要要要要要要要要要要要要要要要要要要'},
					{title: '整挺好吧', summary: '摘要要要要要要要要要要要要要要要要要要要要要要'},
					{title: '整挺好吧', summary: '摘要要要要要要要要要要要要要要要要要要要要要要'},
					{title: '整挺好吧', summary: '摘要要要要要要要要要要要要要要要要要要要要要要'},
					{title: '整挺好吧', summary: '摘要要要要要要要要要要要要要要要要要要要要要要'},
					{title: '整挺好吧', summary: '摘要要要要要要要要要要要要要要要要要要要要要要'}
				],
				me:[
					
				]
			}
		},
		
		onLoad(option) {
			let that = this;
			this.me = uni.getStorageSync('xm-user');
			uni.request({
				url: config.baseUrl + '/users/selectById?id=' + option.userId,
				method: 'GET',
				success(res) {
					console.log(res);
					that.userprof = res.data;
				}
			})
			uni.request({
				url: config.baseUrl + '/note/findByUser?user_id=' + option.userId,
				method:'GET',
				success(res) {
					console.log(res);
					that.notes = res.data;
				}
			})
		},
		
		methods: {
			goNoteView(noteId, fileName){
				uni.navigateTo({
					url:'/pages/noteView/noteView?noteId=' + noteId + '&FileName=' + fileName
				})
			},
			
			addFriend(){
				let that = this;
				
				let form0 = {
					send_id : that.me.id,
					receive_id: that.userprof.id,
					text: '',
					type: 0
				}
				
				let form = JSON.parse(JSON.stringify(form0));
				
				//不能重复申请，发消息
				
				uni.request({
					url: config.baseUrl + '/message/add',
					method:'POST',
					data: form,
					
					success(res){
						
					}
				})
			},
			
			sendMessage(){
				uni.navigateTo({
			
					url:  '/pages/dialogue/dialogue?data=' + this.userprof.id,
				})
				console.log('发消息')
			}
		}
	}
</script>

<style scoped>
	.Box {
		display: flex;
		background-color: #fff;
		padding: 80rpx;
		border-radius: 30rpx;
		box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, .1);
		margin-bottom: 5%;
	}
	
	.Box1 {
		background-color: #fff;
		padding: 60rpx;
		border-radius: 30rpx;
		box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, .1);
		margin-bottom: 5%;
	}
	
	.userDetail {
		margin-left: 8%;
		display: flex;
		flex-direction: column;
		justify-content: space-around;
	}
	
	.note {
		background-color: #f8f8f8;
		margin-top: 10px;
		padding: 10px;
		border-radius: 5px;
		word-wrap: break-word;
	}
	
	.title {
		font-weight: bold;
	}
	
	.summary {
		margin-top: 5px;
		color: #666;
	}
</style>
